package cn.youqu.happy.module.youqu.dal.mysql.userActivity;

import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.framework.mybatis.core.mapper.BaseMapperX;
import cn.youqu.happy.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.youqu.happy.module.youqu.controller.admin.userActivity.vo.UserActivityExportReqVO;
import cn.youqu.happy.module.youqu.controller.admin.userActivity.vo.UserActivityPageReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userActivity.UserActivityDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * 用户发起活动 Mapper
 *
 * @author 王其岩 20112001045
 */
@Mapper
public interface UserActivityMapper extends BaseMapperX<UserActivityDO> {
    UserActivityDO findOneByUidAndId(@Param("uid") Long uid, @Param("id") Integer id);

    int updateActivityStatusById(@Param("updatedActivityStatus") Integer updatedActivityStatus, @Param("id") Integer id);

    int updateActivityStatusAndRemarkById(@Param("updatedActivityStatus") Integer updatedActivityStatus, @Param("updatedRemark") String updatedRemark, @Param("id") Integer id);

    List<UserActivityDO> findAllByEndTimeAndActivityStatus(@Param("endTime") Date endTime, @Param("activityStatus") Integer activityStatus);

    List<UserActivityDO> selectQuickJoinList(@Param("list") List<Integer> activityIds);

    default PageResult<UserActivityDO> selectPage(UserActivityPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserActivityDO>()
                .eqIfPresent(UserActivityDO::getActivityId, reqVO.getActivityId())
                .eqIfPresent(UserActivityDO::getUid, reqVO.getUid())
                .likeIfPresent(UserActivityDO::getActivityName, reqVO.getActivityName())
                .eqIfPresent(UserActivityDO::getTeamSlogan, reqVO.getTeamSlogan())
                .eqIfPresent(UserActivityDO::getAddress, reqVO.getAddress())
                .eqIfPresent(UserActivityDO::getDetail, reqVO.getDetail())
                .eqIfPresent(UserActivityDO::getCurrentPartners, reqVO.getCurrentPartners())
                .eqIfPresent(UserActivityDO::getMaxPartners, reqVO.getMaxPartners())
                .eqIfPresent(UserActivityDO::getMinPartners, reqVO.getMinPartners())
                .betweenIfPresent(UserActivityDO::getAppointTime, reqVO.getBeginAppointTime(), reqVO.getEndAppointTime())
                .betweenIfPresent(UserActivityDO::getEndTime, reqVO.getBeginEndTime(), reqVO.getEndEndTime())
                .eqIfPresent(UserActivityDO::getActivityStatus, reqVO.getActivityStatus())
                .betweenIfPresent(UserActivityDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserActivityDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserActivityDO::getId));
    }

    default List<UserActivityDO> selectList(UserActivityExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserActivityDO>()
                .eqIfPresent(UserActivityDO::getActivityId, reqVO.getActivityId())
                .eqIfPresent(UserActivityDO::getUid, reqVO.getUid())
                .likeIfPresent(UserActivityDO::getActivityName, reqVO.getActivityName())
                .eqIfPresent(UserActivityDO::getTeamSlogan, reqVO.getTeamSlogan())
                .eqIfPresent(UserActivityDO::getAddress, reqVO.getAddress())
                .eqIfPresent(UserActivityDO::getDetail, reqVO.getDetail())
                .eqIfPresent(UserActivityDO::getCurrentPartners, reqVO.getCurrentPartners())
                .eqIfPresent(UserActivityDO::getMaxPartners, reqVO.getMaxPartners())
                .eqIfPresent(UserActivityDO::getMinPartners, reqVO.getMinPartners())
                .betweenIfPresent(UserActivityDO::getAppointTime, reqVO.getBeginAppointTime(), reqVO.getEndAppointTime())
                .betweenIfPresent(UserActivityDO::getEndTime, reqVO.getBeginEndTime(), reqVO.getEndEndTime())
                .eqIfPresent(UserActivityDO::getActivityStatus, reqVO.getActivityStatus())
                .betweenIfPresent(UserActivityDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserActivityDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserActivityDO::getId));
    }

}
